package com.breakfast.fun.ui.user.feedback;

import com.breakfast.fun.data.entity.user.Result;
import com.breakfast.fun.util.Api;
import com.breakfast.fun.util.T;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yukai on 16/9/26.
 */

public class OrderFeedBackPresenter extends OrderFeedBackContract.Presenter {
    @Override
    public void submitFeed(String orderId, String content) {
        Map<String, String> map = Api.getInstance().getBaseParams();

        map.put("action", "complaints");
        map.put("orderId", orderId);
        map.put("content", content);

        showLoadingDialog(true);

        rxManager.add(model.getFeedModel(map)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new Subscriber<Result>() {
                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        T.show("提交失败");
                        hideLoadingDialog();
                        e.printStackTrace();
                    }

                    @Override
                    public void onNext(Result result) {
                        if (result.isSuccess()) {
                            view.feedSuccess();
                        } else {
                            T.show(result.getMsg());
                        }
                        hideLoadingDialog();
                    }

                }));
    }

    @Override
    public void onStart() {

    }
}
